import { Component } from '@angular/core';

import { NavParams, ViewController } from 'ionic-angular';

import { TaskDetailService } from './detail.service';

import { Config } from '../../../providers/config';

import _ from 'lodash';


@Component({
  selector: 'page-task-zcmx',
  templateUrl: './zcmx.html',
  providers: [TaskDetailService]
})
export class ZcmxPage {
	moa_page_name: any = "page-task-zcmx";
  moa_page_explain: any = "资产卡片";

  // 流程实例ID
  bosid;
  zcmsList = [];

  constructor(
    public navParams: NavParams,
    public viewCtrl: ViewController,
    public detailService: TaskDetailService
  ) {
    this.bosid = this.navParams.get('bosid');
    //this.bosid = "816373";
    this.detailService.getZcmxDeatail(this.bosid).subscribe(data => {
      console.log(data);
      //this.dataFomate(data);
      if(data){
        this.zcmsList = data;
      }
    })

  }

  complete() {
    this.dismiss();
  }

  dismiss(data?: any) {
    // using the injected ViewController this page
    // can "dismiss" itself and pass back data
    this.viewCtrl.dismiss(data);
  }

  checkIsSelected(item) {
    item.isShow = !item.isShow;
  }

  // "资产分类":"",
  //       "资产名称":"",
  //       "资产单价":"",
  //       "使用部门":"",
  //       "使用人":"",
  //       "存放地点":""
  dataFomate(dataList) {
    var that = this;
      let entryList = dataList[0].fieldValueMap.entry;
      let temp = {};
      temp["fname"] = "资产名称：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "zcname";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "规格与型号：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "guigexh";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "资产编号：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "bosnum";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "用友编号：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "twono";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "资产单价：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "zcprice";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "净值：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "stringId1";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "使用部门：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "userpart";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "使用人：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "username";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "使用状况：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "state";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "购置日期：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "dreserved3";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "存放地点：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "saler";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "使用年限：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "useyear";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "累计使用年限（月）：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "stringId4";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "资产类别：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "zctype";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "资产细目：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "third";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "登记人：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "author";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "登记日期：";
      temp["fvalue"] = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "dreserved1";
      })["value"]["$value"];
      that.zcmsList.push(temp);

      // temp = {};
      // temp["fname"] = "资产数量：";
      // temp["fvalue"] = _.find(entryList,function(entry){
      //   return entry["key"]["$value"] == "zcnum";
      // })["value"]["$value"];
      // that.zcmsList.push(temp);

      // temp = {};
      // temp["fname"] = "资产总金额：";
      // temp["fvalue"] = _.find(entryList,function(entry){
      //   return entry["key"]["$value"] == "totalzc";
      // })["value"]["$value"];
      // that.zcmsList.push(temp);

      // temp = {};
      // temp["fname"] = "资产子目：";
      // temp["fvalue"] = _.find(entryList,function(entry){
      //   return entry["key"]["$value"] == "second";
      // })["value"]["$value"];
      // that.zcmsList.push(temp);

      temp = {};
      temp["fname"] = "备注：";
      let temp1 = _.find(entryList,function(entry){
        return entry["key"]["$value"] == "stringId6";
      })["value"];

      temp["fvalue"] = temp1 ? temp1["$value"] : "";
      that.zcmsList.push(temp);
  }
}
